/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Entity.Etbl_Package_tour_foods;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author MrKoi
 */
public class DALtbl_Package_tour_foods extends BaseConnection{
    CallableStatement clbStm=null;
    ResultSet rs=null;
      public boolean addtbl_Package_tour_foods(Etbl_Package_tour_foods obj){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Package_tour_foods_add(?,?)}");
            clbStm.setInt("foodId", obj.getFoodId());
            clbStm.setInt("packagetour_Id", obj.getPackagetour_Id());
            clbStm.execute();
            clbStm.close();
            releaseConnection();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Package_tour_foods.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
      
      }
      
      public boolean edittbl_Package_tour_foods(Etbl_Package_tour_foods obj){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Package_tour_foods_update(?,?,?)}");
            clbStm.setInt("tourfoods_Id", obj.getTourfoods_Id());
            clbStm.setInt("foodId", obj.getFoodId());
            clbStm.setInt("packagetour_Id", obj.getPackagetour_Id());
            clbStm.execute();
            clbStm.close();
            releaseConnection();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Package_tour_foods.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
      }
      
      public boolean deletetbl_Package_tour_foods(int tourfoods_Id){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Package_tour_foods_delete(?)}");
            clbStm.setInt("tourfoods_Id",tourfoods_Id);              
            clbStm.execute();
            clbStm.close();
            releaseConnection();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Package_tour_foods.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
      }
      
      public Etbl_Package_tour_foods getOnetbl_Package_tour_foods(int tourfoods_Id){
          Etbl_Package_tour_foods obj=new Etbl_Package_tour_foods();
          try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Package_tour_foods_get(?)}");
            clbStm.setInt("tourfoods_Id",tourfoods_Id);              
            rs=clbStm.executeQuery();            
            while(rs.next()){                            
                obj.setTourfoods_Id(rs.getInt("tourfoods_Id"));
                obj.setFoodId(rs.getInt("foodId"));
                obj.setFoodName(rs.getString("food_name"));
                obj.setPackagetour_Id(rs.getInt("packagetour_Id"));
                obj.setPackagetour_Name(rs.getString("packagetour_name"));                
            }            
            clbStm.close();
            rs.close();
            releaseConnection();
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Package_tour_foods.class.getName()).log(Level.SEVERE, null, ex);
            
        }finally{
              return obj;
          }
      }
      
      public ArrayList getListPackage_tour_foods(String orderBy, String ASCorDESC, String WhereClause, int PagingIndex, int PagingSize){
        try {
            ArrayList arrPackage_tour_foodsList=new ArrayList();
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Package_tour_foods_getpaged(?,?,?,?,?)}");
            clbStm.setString("OrderBy", orderBy);
            clbStm.setString("TangGiam", ASCorDESC);
            clbStm.setString("WhereClause", WhereClause);
            clbStm.setInt("PageIndex", PagingIndex);
            clbStm.setInt("PageSize", PagingSize);
            rs=clbStm.executeQuery();
            DALTotalPageIndex.getTotalPage("tbl_Package_tour_foods", WhereClause, PagingSize);
            while(rs.next()){
                Etbl_Package_tour_foods obj=new Etbl_Package_tour_foods();
                obj.setTourfoods_Id(rs.getInt("tourfoods_Id"));
                obj.setFoodId(rs.getInt("foodId"));
                obj.setFoodName(rs.getString("food_name"));
                obj.setPackagetour_Id(rs.getInt("packagetour_Id"));
                obj.setPackagetour_Name(rs.getString("packagetour_name"));
                arrPackage_tour_foodsList.add(obj);
            }
            clbStm.close();
            rs.close();
            releaseConnection();
            return arrPackage_tour_foodsList;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Package_tour_foods.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}
